package com.example.download.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.example.download.R
import androidx.recyclerview.widget.RecyclerView
import com.example.download.bean.setting_item



class setting_itemAdapter (private val settingItemlistList: List<setting_item>,
                           private val listener: OnItemClickListener
) : RecyclerView.Adapter<setting_itemAdapter.ViewHolder>() {
    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val iv_si_illustration: ImageView = itemView.findViewById(R.id.iv_si_illustration)
        val iv_si_next: ImageView = itemView.findViewById(R.id.iv_si_next)
        val tv_si_title: TextView = itemView.findViewById(R.id.tv_si_title)
        val tv_si_content: TextView = itemView.findViewById(R.id.tv_si_content)
        val tv_si_language: TextView = itemView.findViewById(R.id.tv_si_language)

    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.setting_item, parent, false)
        return ViewHolder(view)
    }
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = settingItemlistList[position]
        holder.iv_si_illustration.setImageResource(item.iv_si_illustration?.toInt()?:0)
        holder.iv_si_next.setImageResource(item.iv_si_next?.toInt()?:0)
        holder.tv_si_title.text = item.tv_si_title
        holder.tv_si_content.text = item.tv_si_content
        holder.tv_si_language.text = item.tv_si_language
        holder.itemView.setOnClickListener {
            listener.onItemClick(item.set_id?.toInt()?:0)
        }
    }
    override fun getItemCount(): Int {
        return settingItemlistList.size
    }
    interface OnItemClickListener {
        fun onItemClick(id: Int)
    }
}